<template>
  <card ref="Card">
    <el-form :model="form" :rules="rules" ref="Form" label-width="100px">
      <el-form-item label="仓库名称" prop="title">
        <el-input v-model="form.title"></el-input>
      </el-form-item>
      <el-form-item label="收件人" prop="senderName">
        <el-input v-model="form.senderName"></el-input>
      </el-form-item>
      <el-form-item label="电话号码" prop="phone">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="收货地址" prop="address">
        <el-input v-model="form.address"></el-input>
      </el-form-item>
    </el-form>
    <custom-editor :editor-key="4" v-model="form.content"></custom-editor>
    <div slot="footer">
      <submit-button ref="Submit" @submit="submit"/>
    </div>
  </card>
</template>

<script>
  import CustomEditor from '@/components/CustomEditor'
  import {getWarehouseAddressApi, editWarehouseAddressApi} from '@/api/website/address'
  import {objectEvaluate} from "@/utils/common";

  export default {
    name: "ChinaAddress",
    components: {CustomEditor},
    data() {
      return {
        form: {
          title: '', // 仓库名称
          senderName: '', // 收件人
          phone: '', // 电话号码
          address: '', // 收货地址
          content: '' // 内容
        }
      }
    },
    mounted() {
      this.getWarehouseAddress()
    },
    methods: {
      getWarehouseAddress() {
        getWarehouseAddressApi().then(result => {
          objectEvaluate(this.form, result.resultParam.addressDto)
        })
      },
      submit() {
        this.$msgBox('确认修改？').then(() => {
          let data = {...this.form};
          this.$refs.Submit.start();
          editWarehouseAddressApi(data).then(() => {
            this.$refs.Submit.stop()
          });
        })
      }
    }
  }
</script>
